package com.ecgsystem.activity;

import java.util.HashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import com.ecgsystem.constants.Constants;
import com.ecgsystem.thread.ThreadGetSignalByFrame;

/**
 * TODO Put here a description of what this class does.
 *
 * @author ANHTUAN.
 *         Created Sep 28, 2012.
 */
public class PatientInfo extends Activity implements Constants{
	/**
	 * TODO Put here a description of this field.
	 */
	public static Context contextPI;
	private String patientName;
	private String patientID;
	private String birthday;
	private String gender;
	
	private static ThreadGetSignalByFrame _thread;
	/**
	 * TODO Put here a description of this field.
	 */
	public static boolean STARTDRAW = false;

	private int clickedPosition = 0;

	private String history;

	private TextView patient_history;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.patient_info);
		contextPI = this;

		Bundle receiveBundle = this.getIntent().getExtras();
		int pos = receiveBundle.getInt("clickedposition");

		HashMap<String, String> patient = PatientList.patientListArr.get(pos);
		this.patientName = patient.get(TAG_PATIENT_NAME);
		this.patientID = patient.get(TAG_PATIENT_ID);
		this.gender = patient.get(TAG_GENDER);
		this.birthday = patient.get(TAG_PATIENT_AGE);

		TextView patientNameTextView = (TextView) findViewById(R.id.textView_name_info);
		patientNameTextView.setText(this.patientName);
		
		TextView patientIDTextView = (TextView) findViewById(R.id.textView_id_info);
		patientIDTextView.setText(this.patientID);

		TextView patientBirthdayTextView = (TextView) findViewById(R.id.textView_birthday_info);
		patientBirthdayTextView.setText(this.birthday.substring(0, 10));

		TextView patientAgeTextView = (TextView)findViewById(R.id.textView_age_info);
		
		
		TextView patientSexTextView = (TextView) findViewById(R.id.textView_gender_info);
		if (this.gender.equals("true")) {
			patientSexTextView.setText("Nam");
		} else {
			patientSexTextView.setText("Nữ");
		}

/*
			public void onClick(View v) {
				StoredSignal.QueueDraw = (ConcurrentLinkedQueue<Float>[]) new ConcurrentLinkedQueue[12];
				for (int i = 0; i < 12; i++) {
					StoredSignal.QueueDraw[i] = new ConcurrentLinkedQueue<Float>();
				}

				_thread = new ThreadGetSignalByFrame(
						MainActivity.conn.getHistoryRecord(PatientInfo.this.clickedPosition)
								.getRecordID());
				_thread.start();
		
				Intent i = new Intent(PatientInfo.this, StoredSignal.class);
	
				startActivity(i);
			}
		});*/
	}

	/**
	 * TODO Put here a description of what this method does.
	 *
	 */
	public void getRecords() {
		MainActivity.conn.getRecord12(MainActivity.conn.getHistoryRecord(
				this.clickedPosition).getRecordID());
	}

	@Override
	public boolean onKeyDown(final int keyCode, final KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Bundle patientList = new Bundle();

			Intent i = new Intent(PatientInfo.this, PatientList.class);
			i.putExtras(patientList);
			startActivity(i);
			finish();
		}
		return true;
	}
	
	public static void stopGetSignal(){
		_thread.shutdown();
	}
}